home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWWindow / Sources / FWFloWin.cpp next >
Encoding:
Text File  |  1996-08-16  |  11.2 KB  |  374 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFloWin.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWFLOWIN_H
  13. #include "FWFloWin.h"
  14. #endif
  15.  
  16. #ifndef FWACQUIR_H
  17. #include "FWAcquir.h"
  18. #endif
  19.  
  20. #ifndef FWPART_H
  21. #include "FWPart.h"
  22. #endif
  23.  
  24. #ifndef FWPRESEN_H
  25. #include "FWPresen.h"
  26. #endif
  27.  
  28. #ifndef FWSHDWIN_H
  29. #include "FWShdWin.h"
  30. #endif
  31.  
  32. #ifndef FWFRAME_H
  33. #include "FWFrame.h"
  34. #endif
  35.  
  36. // ----- Foundation Includes -----
  37.  
  38. #ifndef FWEXCLIB_H
  39. #include "FWExcLib.h"
  40. #endif
  41.  
  42. #ifndef   FWRESACC_H
  43. #include "FWResAcc.h"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef SOM_ODWindow_xh
  49. #include <Window.xh>
  50. #endif
  51.  
  52. #ifndef SOM_ODStorageUnit_xh
  53. #include <StorageU.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODWindowState_xh
  57. #include <WinStat.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODSession_xh
  61. #include <ODSessn.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODInfo_xh
  65. #include <Info.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODPart_xh
  69. #include <Part.xh>
  70. #endif
  71.  
  72. #if defined(__MWERKS__) && GENERATING68K
  73. // A hack to work around a bug
  74. #pragma import list somGetGlobalEnvironment
  75. #endif
  76.  
  77. //========================================================================================
  78. //    Runtime Info
  79. //========================================================================================
  80.  
  81. #ifdef FW_BUILD_MAC
  82. #pragma segment fwwindow
  83. #endif
  84.  
  85. //========================================================================================
  86. //    Static Members
  87. //========================================================================================
  88.  
  89. FW_TOrderedCollection<FW_CPrivSharedWindow>* FW_CFloatingWindow::gSharedWindows = NULL;
  90.  
  91. //========================================================================================
  92. // Struct FW_SPrivWindowParameters
  93. //========================================================================================
  94. //    This structure is used by FW_CFloatingWindow when the creation of the ODWindow is differed until
  95. //    the window is shown
  96.  
  97. struct FW_SWindowParameters {
  98.  
  99.     FW_DECLARE_AUTO(FW_SWindowParameters)        // because there is a FW_CString255 field which is 
  100.                                                 // an autodestruct
  101.     
  102.     FW_CPart*                 fThePart;
  103.     ODFrame*                fParentFrame;
  104.     FW_Boolean                fPersistent;
  105.     ODTypeToken             fViewType;
  106.     FW_CPresentation*         fPresentation;
  107.     FW_CString255             fWindowTitle;
  108.     FW_CPoint                 fInteriorSize;
  109.     FW_CPoint                 fPosition;
  110.     FW_WindowStyle             fStyle;
  111. };
  112.  
  113. //========================================================================================
  114. //    Template Instantiations
  115. //========================================================================================
  116.  
  117. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CFloatingWindow)
  118. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CFloatingWindow)
  119.  
  120. #ifdef FW_USE_TEMPLATE_PRAGMAS
  121.  
  122. #pragma template_access public
  123. #pragma template FW_TOrderedCollection<FW_CFloatingWindow>
  124. #pragma template FW_TOrderedCollectionIterator<FW_CFloatingWindow>
  125.  
  126. #endif
  127.  
  128. //========================================================================================
  129. // struct FW_SWindowParameters
  130. //========================================================================================
  131.  
  132. FW_DEFINE_AUTO(FW_SWindowParameters)
  133.  
  134. //========================================================================================
  135. // CLASS FW_CFloatingWindow
  136. //========================================================================================
  137.  
  138. FW_DEFINE_CLASS_M1(FW_CFloatingWindow, FW_CWindow)
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // FW_CFloatingWindow::FW_CFloatingWindow
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CFloatingWindow::FW_CFloatingWindow(Environment* ev, 
  145.                                         FW_CPart* part,
  146.                                         FW_CPresentation* presentation,
  147.                                         const FW_CString& windowTitle,
  148.                                         const FW_CPoint& interiorSize,
  149.                                         const FW_CPoint& position,
  150.                                         FW_Boolean hasCloseBox) :
  151.     FW_CWindow(ev, part, (ODID)kODNULLID),
  152.     fWindowParameters(NULL),
  153.     fSharedWindow(NULL),
  154.     fRootFrame(NULL),
  155.     fPart(part)
  156. {    
  157.     FW_ASSERT(presentation != NULL);
  158.     ODTypeToken presentationType = presentation->GetPresentationType(ev);
  159.  
  160.     if (gSharedWindows == NULL)
  161.         gSharedWindows = FW_NEW(FW_TOrderedCollection<FW_CPrivSharedWindow>, ());
  162.     else
  163.     {    
  164.         FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(gSharedWindows);
  165.         for (FW_CPrivSharedWindow* sharedRec = ite.First();
  166.              ite.IsNotComplete();
  167.              sharedRec = ite.Next())
  168.         {
  169.             if (sharedRec->GetPresentationType() == presentationType)
  170.             {
  171.                 fSharedWindow = sharedRec;
  172.                 SetID(ev, fSharedWindow->GetWindowID());
  173.                 break;
  174.             }
  175.         }
  176.     }
  177.     
  178.     // ----- If no record yet then create one -----
  179.     if (fSharedWindow == NULL)
  180.     {
  181.         fSharedWindow = new FW_CPrivSharedWindow(presentationType);
  182.         gSharedWindows->AddLast(fSharedWindow);
  183.     }
  184.  
  185.     fSharedWindow->AddWindow(this);
  186.  
  187.     // ----- If the window has not yet been created then save the parameters for later -----
  188.     if (fSharedWindow->GetWindowID() == kODNULLID)
  189.     {
  190.         fWindowParameters = FW_NEW(FW_SWindowParameters, ());
  191.         fWindowParameters->fThePart            = part;
  192.         fWindowParameters->fParentFrame     = NULL;
  193.         fWindowParameters->fPersistent         = FALSE;
  194.         fWindowParameters->fViewType         = FW_CPart::gViewAsFrameToken;
  195.         fWindowParameters->fPresentation     = presentation;
  196.         fWindowParameters->fWindowTitle     = windowTitle;
  197.         fWindowParameters->fInteriorSize     = interiorSize;
  198.         fWindowParameters->fPosition         = position;
  199.         fWindowParameters->fStyle             = FW_kFloatingWindow | (hasCloseBox ? FW_kHasCloseBox : 0);
  200.     }
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // FW_CFloatingWindow::~FW_CFloatingWindow
  205. //----------------------------------------------------------------------------------------
  206.  
  207. FW_CFloatingWindow::~FW_CFloatingWindow()
  208. {
  209.     Environment* ev = somGetGlobalEnvironment();
  210.     
  211.     if (fRootFrame && (fRootFrame->GetODFrame(ev) == NULL))
  212.         delete fRootFrame;            // the RooFrame is owned by the window if its ODFrame is NULL
  213.             
  214.     delete fWindowParameters;        // fine even if NULL
  215.  
  216.     if (fSharedWindow != NULL)
  217.     {
  218.         fSharedWindow->RemoveWindow(this);
  219.         
  220.         if (fSharedWindow->CountWindow() == 0)
  221.         {
  222.             gSharedWindows->Remove(fSharedWindow);                
  223.             delete fSharedWindow;    // will delete fWindowList
  224.             
  225.             if (gSharedWindows->Count() == 0)
  226.             {
  227.                 delete gSharedWindows;
  228.                 gSharedWindows = NULL;
  229.             }
  230.         }
  231.     }
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // FW_CFloatingWindow::AcquireODWindow
  236. //----------------------------------------------------------------------------------------
  237.  
  238. ODWindow* FW_CFloatingWindow::AcquireODWindow(Environment* ev) const
  239. {
  240.     if (fSharedWindow->GetWindowID() == kODNULLID)
  241.     {
  242.         FW_ASSERT(fWindowParameters != NULL);
  243.         
  244.         FW_CFloatingWindow* self = (FW_CFloatingWindow*)this;        
  245.  
  246.         ODWindow* odWindow = self->PrivCreateODWindow(ev, 
  247.                                                     fWindowParameters->fThePart, 
  248.                                                     fWindowParameters->fParentFrame, 
  249.                                                     fWindowParameters->fPersistent, 
  250.                                                     fWindowParameters->fViewType,
  251.                                                     fWindowParameters->fPresentation, 
  252.                                                     fWindowParameters->fWindowTitle, 
  253.                                                     fWindowParameters->fInteriorSize, 
  254.                                                     fWindowParameters->fPosition,
  255.                                                     fWindowParameters->fStyle);
  256.         
  257.         self->SetID(ev, odWindow->GetID(ev));
  258.  
  259.         self->PrivOpenWindow(ev, odWindow);
  260.  
  261.         delete fWindowParameters;
  262.         self->fWindowParameters = NULL;    
  263.  
  264.         self->fRootFrame = FW_CFrame::ODtoFWFrame(ev, odWindow->GetRootFrame(ev));
  265.         
  266.         return odWindow;
  267.     }
  268.     else
  269.         return FW_CWindow::AcquireODWindow(ev);
  270. }
  271.  
  272. //----------------------------------------------------------------------------------------
  273. // FW_CFloatingWindow::IsFloating
  274. //----------------------------------------------------------------------------------------
  275.  
  276. FW_Boolean FW_CFloatingWindow::IsFloating(Environment* ev) const
  277. {
  278. FW_UNUSED(ev);
  279.     return TRUE;
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. // FW_CFloatingWindow::TransferOwnership
  284. //----------------------------------------------------------------------------------------
  285.  
  286. void FW_CFloatingWindow::TransferOwnership(Environment* ev, 
  287.                                         ODWindowState* windowState,
  288.                                         ODPart* newOwner)
  289. {
  290.     FW_ASSERT(newOwner != NULL);
  291.     
  292.     if (gSharedWindows == NULL)
  293.         return;
  294.         
  295.     FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(FW_CFloatingWindow::gSharedWindows);
  296.     for (FW_CPrivSharedWindow* sharedWindow = ite.First();
  297.          ite.IsNotComplete();
  298.          sharedWindow = ite.Next())
  299.     {
  300.         if (sharedWindow->GetWindowID() != kODNULLID)
  301.         {
  302.             FW_CAcquiredODWindow aqODWindow = windowState->AcquireWindow(ev, sharedWindow->GetWindowID());
  303.             ODFrame* rootFrame = aqODWindow->GetRootFrame(ev);
  304.             FW_CAcquiredODPart oldOwner = rootFrame->AcquirePart(ev);
  305.             if (newOwner != oldOwner)
  306.             {
  307.                 rootFrame->Acquire(ev);    // Release on rootframe is called before acquire                
  308.                 FW_CAcquiredODFrame aqFrame(rootFrame);
  309.                 
  310.                 // ----- find the right FW_CFloating Window
  311.                 FW_CFloatingWindow* newFloatingWindow = sharedWindow->GetFloatingWindow(ev, newOwner);
  312.  
  313.                 // ----- Set the RefCon field (this is where FW_CFrame will find the FW_CWindow pointer)
  314. #ifdef FW_BUILD_MAC
  315.                 ::SetWRefCon(aqODWindow->GetPlatformWindow(ev), (long)newFloatingWindow);
  316. #endif
  317. #ifdef FW_BUILD_WIN
  318.                 ::SetProp(aqODWindow->GetPlatformWindow(ev), "ODF:Window", (HANDLE)newFloatingWindow);
  319. #endif
  320.  
  321.                 // ----- Change the owner of the frame -----
  322.                 rootFrame->ChangePart(ev, newOwner);
  323.                 
  324.                 // ----- cache the FW_CFrame -----
  325.                 FW_ASSERT(newFloatingWindow->GetID(ev) == sharedWindow->GetWindowID());
  326.                 if (newFloatingWindow->fRootFrame == NULL)
  327.                     newFloatingWindow->fRootFrame = FW_CFrame::ODtoFWFrame(ev, rootFrame);
  328. #ifdef FW_DEBUG
  329.                 else
  330.                     FW_ASSERT(newFloatingWindow->fRootFrame == FW_CFrame::ODtoFWFrame(ev, rootFrame));
  331. #endif        
  332.                 // ----- Force an update if shown -----        
  333.                 if (aqODWindow->IsShown(ev))
  334.                     aqODWindow->Update(ev);
  335.             }
  336.         }
  337.     }
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. // FW_CFloatingWindow::GetID
  342. //----------------------------------------------------------------------------------------
  343.  
  344. ODID FW_CFloatingWindow::GetID(Environment* ev) const
  345. {
  346. FW_UNUSED(ev);
  347.     return fSharedWindow->GetWindowID();
  348. }
  349.  
  350. //----------------------------------------------------------------------------------------
  351. // FW_CFloatingWindow::SetID
  352. //----------------------------------------------------------------------------------------
  353.  
  354. void FW_CFloatingWindow::SetID(Environment* ev, ODID windowID)
  355. {
  356.     fSharedWindow->SetWindowID(windowID);    
  357.     FW_CWindow::SetID(ev, windowID);
  358. }
  359.  
  360. //---------------------------------------------------------------------------------------
  361. //    FW_CFloatingWindow::HideShowFloatingWindows
  362. //---------------------------------------------------------------------------------------
  363.  
  364. void FW_CFloatingWindow::HideShowFloatingWindows(Environment *ev, ODWindowState* windowState, FW_Boolean state)
  365. {            
  366.     FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(FW_CFloatingWindow::gSharedWindows);
  367.     for (FW_CPrivSharedWindow* sharedWindow = ite.First();
  368.          ite.IsNotComplete();
  369.          sharedWindow = ite.Next())
  370.     {
  371.         sharedWindow->HideShow(ev, windowState, state);
  372.     }
  373. }
  374.